let reg_vm = new Vue({
    el: "#reg",
    data: {
        username: '',
        nickname: '',
        password: '',
        confirm: '',
        message: '',
        hasError: false
    },
    methods: {
        reg: function () {
            console.log('Submit');
            let form = new FormData();
            form.append("username", this.username);
            form.append("nickname", this.nickname);
            form.append("password", this.password);
            form.append("confirm", this.confirm);
            console.log(form);
            console.log("昵称:" + this.nickname)
            console.log("用户名:" + this.username)
            console.log("密码:" + this.password)
            console.log("确认:" + this.confirm)
            if (this.password != this.confirm) {
                this.message = "确认密码不一致！";
                this.hasError = true;
                return;
            }
            axios({
                method: 'post',
                url: '/reg',
                data: form
            })
                .then(function (r) {
                    console.log("|" + r.status + "|" + "OK" + "|");
                    if (r.data == "ok") {
                        console.log("注册成功");
                        console.log(r.data);
                        reg_vm.hasError = false;
                        alert("注册成功,请登录!")
                        location.reload();
                    } else {
                        console.log("报错:" + r.data);
                        reg_vm.hasError = true;
                        if (r.data.length < 15) {
                            reg_vm.message = r.data;
                        } else {
                            reg_vm.message = "未知错误,请联系管理员";
                        }

                    }
                });
        }
    }
});